import Vue from 'vue'
import Router from 'vue-router'
// 引入组件
import ceshi from '../pages/ceshi'
import Login from '../components/Login'
import Home from '../pages/Home'
import ceshi1 from '../pages/ceshi1'
// 可信存证相关路由引入
import exsitsurvey from '../pages/ExsitingAndput/exsitsurvey'
import exsiting from '../pages/ExsitingAndput/exsiting'
import main from '../pages/ExsitingAndput/main'
import buy from '../pages/Business/buy'
// 版权保护
import copyrightprotect from '../pages/CopyrightProtect/copyrightprotect'
// 版权保护子路由
import copyrightoverview from '../pages/CopyrightProtect/children/copyrightoverview'
import protectmain from '../pages/CopyrightProtect/children/protectmain'
// 发行
import frame from '../pages/Business/frame'
// 发行子路由
import childrensummary from '../pages/Business/main/childrensummary'
import childrenmain from '../pages/Business/main/childrenmain'
// 详情页
import detaileddisplay from '../pages/Business/detaileddisplay'

// 我的资产
import myassets from '../pages/Myassets/myassets'
import mydetaileddisplay from '../pages/Myassets/mydetaileddispaly'

Vue.use(Router)



const router = new Router({
        routes: [{
                path: '/',
                name: 'Login',
                component: Login,
                // 添加路由验证
                meta: { isRouterAuth: false }
            },
            // 主页
            {
                path: '/Home',
                name: 'Home',
                component: Home,
                meta: { isRouterAuth: true }
            },
            // 同级测试路由
            {
                path: '/ceshi',
                name: 'ceshi',
                component: ceshi,
                meta: { isRouterAuth: true },
                children: [{
                        // 可信存证概述
                        path: 'exsitsurvey',
                        name: 'exsitsurvey',
                        component: exsitsurvey,
                        meta: { isRouterAuth: true },
                    },
                    // 可信存证
                    {
                        path: 'exsiting',
                        name: 'exsiting',
                        component: exsiting,
                        meta: { isRouterAuth: true },
                    },
                    // 默认主页
                    {
                        path: '/',
                        name: 'main',
                        component: main,
                        meta: { isRouterAuth: true },
                    },
                    // 交易主页
                    {
                        path: 'buy',
                        name: 'buy',
                        component: buy,
                        meta: { isRouterAuth: true },
                    },
                    // 详情展示
                    {
                        path: 'detaileddisplay',
                        name: 'detaileddisplay',
                        component: detaileddisplay,
                        meta: { isRouterAuth: true },
                    },
                    // 版权保护
                    {
                        path: 'copyrightprotect',
                        name: 'copyrightprotect',
                        component: copyrightprotect,
                        meta: { isRouterAuth: true },
                        // 概述与主要功能
                        children: [
                            // 默认展示概述
                            {
                                path: '/',
                                name: 'copyrightoverview',
                                component: copyrightoverview,
                                meta: { isRouterAuth: true },
                            }, {
                                path: 'protectmain',
                                name: 'protectmain',
                                component: protectmain,
                                meta: { isRouterAuth: true },
                            }

                        ]
                    },
                    // 发行
                    {
                        path: 'frame',
                        name: 'frame',
                        component: frame,
                        meta: { isRouterAuth: true },
                        // 下面概述
                        children: [
                            // 概述

                            {
                                path: '/',
                                name: 'childrensummary',
                                component: childrensummary,
                                meta: { isRouterAuth: true },
                            },
                            // 主体
                            {
                                path: 'childrenmain',
                                name: 'childrenmain',
                                component: childrenmain,
                                meta: { isRouterAuth: true },
                            }
                        ]
                    },
                    // 我的资产展示界面
                    {
                        path: 'myassets',
                        name: 'myassets',
                        component: myassets,
                        meta: { isRouterAuth: true },
                    },
                    {
                        path: 'mydetaileddisplay',
                        name: 'mydetaileddisplay',
                        component: mydetaileddisplay,
                        meta: { isRouterAuth: true },
                    }
                ]
            },
            // 第二个测试路由
            {
                path: '/ceshi1',
                name: 'ceshi1',
                component: ceshi1,
                meta: { isRouterAuth: true },
            }

        ],
    })
    // 路由守卫
router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('token');
    if (to.meta.isRouterAuth) { // 判断当前路由是否需要路由验证
        if (token) { // 判断当前的token是否存在
            next() // 存在继续执行
        } else {
            next('/') //不存在需要跳到登陆页
        }
    } else { // 不需要验证路由，继续执行
        next()
    }
})
export default router;